﻿using AutoMapper;
using B.S.DataBase.MyProject.Domain;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using B.S.DataBase.MyRead.API.Appicant.Command;
using B.S.DataBase.MyRead.API.Appicant.Command.QingJia;
using MediatR;

namespace B.S.DataBase.MyRead.API.Appicant.CommandHandler.QingJia
{
    public class DepNameQueryCommandHandler : IRequestHandler<DepNameQueryCommand, APIResult<List<User>>>
    {
        private readonly IBaseRepository<User> uRep;
        private readonly IMapper mapper;

        public DepNameQueryCommandHandler(IBaseRepository<User> uRep, IMapper mapper)
        {
            this.uRep = uRep;
            this.mapper = mapper;
        }


        public async Task<APIResult<List<User>>> Handle(DepNameQueryCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<User>> result = new APIResult<List<User>>();
            result.Code = APIEnum.查询成功;
            result.Msg = APIEnum.查询成功.ToString();
            var list = uRep.GetAll().Result.Where(x => x.DepId == request.DepId&&x.HaoId==request.HaoId).ToList();
            result.data = list;
            return await Task.FromResult(result);


        }
    }
}
